package wheel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import wheel.Computer.WordSource;

public class Guess {
	private static final Map<Computer.WordSource, Double> wordSourceWeights;
	static {
        HashMap<Computer.WordSource, Double> map = new HashMap<Computer.WordSource, Double>();
        map.put(Computer.WordSource.LW_CAT_AND_PW, 0.05);
        map.put(Computer.WordSource.LW_OTHER_AND_PW, 0.07);
        map.put(Computer.WordSource.LW_CAT_NOT_PW, 0.10);
        map.put(Computer.WordSource.LW_OTHER_NOT_PW, 0.10);
        map.put(Computer.WordSource.POPULAR_WORDS, 0.12);
        map.put(Computer.WordSource.WORDNET, 0.20);
        map.put(Computer.WordSource.LINUX_WORDS, 0.07);
        map.put(Computer.WordSource.INVOKE_WORDS, 0.05);
        wordSourceWeights = Collections.unmodifiableMap(map);
    }

	private String text;
	private ArrayList<Computer.WordSource> sources;
	
	public Guess() {
		this.text = "";
		this.sources = new ArrayList<Computer.WordSource>();
	}

	public Guess(String text) {
		this.text = text;
		this.sources = new ArrayList<Computer.WordSource>();
	}
	
	public Guess(String text, WordSource wordSource) {
		this.text = text;
		this.sources = new ArrayList<Computer.WordSource>();
		this.sources.add(wordSource);
	}
	
	public Guess(String text, ArrayList<WordSource> sources) {
		this.text = text;
		this.sources = sources;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public ArrayList<Computer.WordSource> getSources() {
		return sources;
	}

	public void setSources(ArrayList<Computer.WordSource> sources) {
		this.sources = sources;
	}

	public double getGuessWeight() {
		double weight = 1.0;
		for(Computer.WordSource source: sources) {
			if ( (source.equals(Computer.WordSource.LW_CAT_AND_PW) || 
				  source.equals(Computer.WordSource.LW_OTHER_AND_PW)) &&
				 !sourcesContains(Computer.WordSource.POPULAR_WORDS) ) {
				weight += wordSourceWeights.get(Computer.WordSource.POPULAR_WORDS);
			}
			weight += wordSourceWeights.get(source);
		}
		return weight;
	}
	
	private boolean sourcesContains(Computer.WordSource source) {
		for( Computer.WordSource s: sources) {
			if (s.equals(source))
				return true;
		}
		return false;
	}
}
